package com.xmy.study.service.impl;

import com.xmy.study.constants.MqConstants;
import com.xmy.study.entity.PerStudentClassType;
import com.xmy.study.respons.ChaStudyPlan;
import com.xmy.study.respons.StudentAllotTier;
import com.xmy.study.service.IMqPushService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqPushServiceImpl implements IMqPushService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 判断是否通关，已通关不算应到
     */
    @Override
    public boolean chaStudyPlanAdd(ChaStudyPlan chaStudyPlan) {
        rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_CHA_STUDY_STATUS_FANOUT, null, chaStudyPlan);
        return true;
    }


    @Override
    public void studentAllotTier(StudentAllotTier studentAllotTier){
        try{
            //先发送到erp，Mq添加好帐号，再从erpMq分发给其它系统
            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_STUDENT_ALLOT_TIER_FANOUT, null, studentAllotTier);
        }catch (Exception e){
            System.out.println("out:"+e.getMessage());
        }
    }

    @Override
    public boolean updateStudentGradeClassTypeId(PerStudentClassType studentClassType){
        try {
            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_STUDENT_GRADE_CLASS_TTYPE_ID_FANOUT, null, studentClassType);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
